package com.manish.tabdemo;
 
import java.util.ArrayList;
import java.util.List; 

import com.manish.tabdemo.R;
import com.manish.tabdemo.R.id;
import com.manish.tabdemo.R.layout;

import android.os.Bundle; 
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;  
import android.content.Intent;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView; 
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

public class CustomlistviewActivity extends Activity {

	private ListView listViewFootballLegend;
	private Context ctx;
    @SuppressLint("NewApi")
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_customlistview);      
        
        ActionBar ab = getActionBar();
        ab.setHomeButtonEnabled(true);
        ab.setDisplayHomeAsUpEnabled(true);
		
        ctx=this;	
		List<RistorantiList> legendList= new ArrayList<RistorantiList>();
		legendList.add(new RistorantiList("La paranza","Via San Michele","navigation_next_item"));
		legendList.add(new RistorantiList("La tana","Via Cavour","navigation_next_item"));
		legendList.add(new RistorantiList("La bussola","Via Campanella","navigation_next_item"));
		legendList.add(new RistorantiList("Trattoria toscana","Via Pescara","navigation_next_item"));
		legendList.add(new RistorantiList("La ciucculella","Via Beccaria","navigation_next_item"));
		legendList.add(new RistorantiList("Vineree","Via Incoronata","navigation_next_item"));

		listViewFootballLegend = ( ListView ) findViewById( R.id.Ristoranti_list);
		listViewFootballLegend.setAdapter( new RistorantiListAdapter(ctx, R.layout.legend_row_item, legendList ) );
    
		// Click event for single list row
		listViewFootballLegend.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				RistorantiList o = (RistorantiList) parent.getItemAtPosition(position);  
				Toast.makeText(CustomlistviewActivity.this, o.getName().toString(), Toast.LENGTH_SHORT).show();
			}
		});		
    } 
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    	onBackPressed();
        return super.onOptionsItemSelected(item);       
    }
    
}
